#include <SFML/Network.hpp>
#include <iostream>


#define PORT 1337

#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600

#define PADDLE_WIDTH 21
#define PADDLE_HEIGHT 70

#define BALL_WIDTH 16
#define BALL_HEIGHT 16

#define BALL_SPEED .007
#define PADDLE_SPEED .1

class GameState
{
public:
	int BallPos[2];
	int PlayerAPos[2];
	int PlayerBPos[2];
};

class Server
{
public:
	Server();
	bool WaitForConnections(void);
private:
	char* ReceiveA(void);
	char* ReceiveB(void);
	sf::SocketUDP recSock;
	sf::IPAddress PlayerA;
	sf::IPAddress PlayerB;

};
Server::Server()
{
	recSock.Bind(PORT);
}

bool Server::WaitForConnections()
{
	std::cout<<"Waiting for Player A"<<std::endl;
	char* data = new char[4];
	while (data!="OPEN")
	{
		data=ReceiveA();
		std::cout<<"Received:"<<data<<std::endl;
	}
	std::cout<<"Player A Connected"<<std::endl;
	
	system("PAUSE");
	return true;
}
char* Server::ReceiveA()
{
	char* recBuffer = new char[4];
	std::size_t size;
	while (recSock.Receive(recBuffer,sizeof(recBuffer),size,PlayerA)!= sf::Socket::Done)
	{}
	char* data = new char[size];
	data=recBuffer;
	return data;
}
char* Server::ReceiveB()
{
	char* recBuffer = new char[128];
	std::size_t size;
	while (recSock.Receive(recBuffer,sizeof(recBuffer),size,PlayerB)!= sf::Socket::Done)
	{}
	return recBuffer;
}